#include <string>
#include <iostream>
#include <windows.h>
#include <tchar.h>
#include "CMainFrame.h"
#include "resource.h"
#include "CWin32Utils/CXinputHelper.h"
#include "CWin32Utils/CTokenUtils.h"

int WINAPI _tWinMain(
    _In_ HINSTANCE hInstance,
    _In_opt_ HINSTANCE hPrevInstance,
    _In_ LPTSTR lpCmdLine,
    _In_ int nShowCmd)
{
    UNREFERENCED_PARAMETER(hInstance);
    UNREFERENCED_PARAMETER(hPrevInstance);
    UNREFERENCED_PARAMETER(lpCmdLine);
    UNREFERENCED_PARAMETER(nShowCmd);

    DWORD dwErr = 0;
    DWORD dwUIAccess = 0;
    CMainFrame dlg;
    dlg.DoModalEx(IDD_DIALOG_MAIN, NULL, TRUE, true);
    return 0;

    if (CTokenUtils::CheckForUIAccess(GetCurrentProcessId(),  &dwErr, &dwUIAccess))
    {
        if (!dwUIAccess)
        {
            _tstring strPath = CTokenUtils::GetModulePath();
            CTokenUtils::CreateProcessWithUIAccess(strPath);
        }
        else
        {
            CMainFrame dlg;
            dlg.DoModalEx(IDD_DIALOG_MAIN, NULL, TRUE, true);
        }
    }

    return 0;
}

int main()
{
    CXInputHelper obj;
    obj.Initialize();

    //obj.SetAxisThreshold(4096, 4096);

#if 0
    obj.SetRawEventCallback([](const GAMEPAD_INPUT_EVENT& event)-> void {
        CXInputHelper::PrintText(_T("Mask: %08X bRight: %d Trigger: %3d Axis: %6d,%6d Data: %d Buttons: %.8X Duration: %6d Axis: (Left: %d Up: %d Right: %d Down: %d)\r\n"),
        event.eButton,
        event.fRight, event.bTrigger, 
        event.sAxisX, event.sAxisY,
        event.curButtonEvent.Event,
        event.curButtonState.Button,
        event.curButtonEvent.uDuration,
        event.curAxisEvent.Left.Event,
        event.curAxisEvent.Up.Event,
        event.curAxisEvent.Right.Event,
        event.curAxisEvent.Down.Event
        );

        }
    );
#endif

    obj.SetMergeEventCallback([](const GAMEPAD_INPUT_EVENT& event)-> void {
        CXInputHelper::PrintText(_T("Mask: %08X bRight: %d Trigger: %3d Axis: %6d,%6d Data: %d Buttons: %.8X Duration: %6d Axis: (Left: %d Up: %d Right: %d Down: %d)\r\n"),
        event.eButton,
        event.fRight, event.bTrigger, 
        event.sAxisX, event.sAxisY,
        event.curButtonEvent.Event,
        event.curButtonState.Button,
        event.curButtonEvent.uDuration,
        event.curAxisEvent.Left.Event,
        event.curAxisEvent.Up.Event,
        event.curAxisEvent.Right.Event,
        event.curAxisEvent.Down.Event
        );

        }
    );

    system("pause");

    return 0;
}
